1 : <?php
2 : if (!defined("PATH_TO_ROOT")) define("PATH_TO_ROOT", "../../../");
3 :
4 : class Database {
5 :
6 : private $db;
7 : private $userID;
8 :
9 : public function Database( $userID ) {
10 14 : global $db;
11 14 : $this->db = $db;
12 14 : $this->userID = (int)$userID;
13 14 : }
14 :
15 : public function fetchEvents() {
16 0 : $user = "SELECT eventID FROM calendar_user WHERE userID = $this->userID";
17 : $team = "SELECT eventID FROM calendar_courses LEFT JOIN user_course "
18 : . "ON calendar_courses.coursesID = user_course.courseID "
19 0 : . "WHERE user_course.userID = $this->userID";
20 : $course = "SELECT eventID FROM calendar_teams LEFT JOIN user_team "
21 : . "ON calendar_teams.teamsID = user_team.team_id "
22 0 : . "WHERE user_team.user_id = $this->userID";
23 0 : $foyer = "SELECT eventID FROM calendar_courses WHERE coursesID=0";
24 :
25 : $sql = "SELECT * FROM calendar WHERE eventid IN ( "
26 0 : . $user . " UNION "
27 0 : . $team . " UNION "
28 0 : . $course . " UNION "
29 0 : . $foyer . ") "
30 0 : . "ORDER BY eventtime ASC";
31 :
32 0 : return $this->db->get_results($sql);
33 : }
34 :
35 : public function authenticate( $userID, $token ) {
36 0 : if ( $token === $this->hash($userID) ) return true;
37 :
38 0 : return false;
39 : }
40 :
41 : public function hash() {
42 2 : $sql = "SELECT Login,regdate,policy_read FROM user WHERE ID=$this->userID";
43 2 : $result = $this->db->get_row($sql);
44 2 : return sha1($result->Login . $result->policy_read . $result->regdate);
45 : }
46 :
47 : public function iCalendarURL() {
48 1 : $sql = "SELECT value FROM settings WHERE name='emod_wsdlpath'";
49 1 : return $this->db->get_var($sql)
50 : . "/calendar/icalendar.php?user="
51 1 : . $_SESSION['userid']
52 1 : . "&token="
53 1 : . $this->hash();
54 : }
55 : }
|